home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_11_06
/
1106112b
< prev
next >
Wrap
Text File
|
1993-04-17
|
1KB
|
59 lines
typedef char * Buffer;
void Buffer_initialize(char ** pointer);
int Buffer_allocate(char ** pointer, size_t size,
char * name);
void Buffer_terminate(char ** pointer);
int some_function(void)
{
Buffer buffer1, buffer2;
int ret1, ret2;
Buffer_initialize(&buffer1);
Buffer_initialize(&buffer2);
if (Buffer_allocate(&buffer1, 1024, "buffer1")
== SUCCESS
&& Buffer_allocate(&buffer2, 1024, "buffer2")
== SUCCESS)
{
/* Do whatever processing is required. */
}
Buffer_terminate(&buffer1);
Buffer_terminate(&buffer2);
}
void Buffer_initialize(Buffer * buffer)
{
*buffer = NULL:
return;
}
int Buffer_allocate(Buffer * pointer, size_t size,
char * name)
{
int return_code = SUCCESS;
*pointer = malloc(size);
if (*pointer == NULL)
{
fprintf(stderr, "Allocation failure for %s size %d",
name, size);
return_code = FAILUE;
}
return return_code;
}
void Buffer_terminate(Buffer * pointer)
{
if (*pointer != NULL)
{
free(*pointer);
*pointer = NULL;
}
return;
}